package com.ruoyi.web.controller.personal;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Appraisal;
import com.ruoyi.system.service.IAppraisalService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 考核申请Controller
 * 
 * @author ruoyi
 * @date 2023-11-13
 */
@RestController
@RequestMapping("/system/appraisal")
public class AppraisalController extends BaseController
{
    @Autowired
    private IAppraisalService appraisalService;

    /**
     * 查询考核申请列表
     */
    @PreAuthorize("@ss.hasPermi('system:appraisal:list')")
    @GetMapping("/list")
    public TableDataInfo list(Appraisal appraisal)
    {
        startPage();
        List<Appraisal> list = appraisalService.selectAppraisalList(appraisal);
        return getDataTable(list);
    }

    /**
     * 导出考核申请列表
     */
    @PreAuthorize("@ss.hasPermi('system:appraisal:export')")
    @Log(title = "考核申请", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Appraisal appraisal)
    {
        List<Appraisal> list = appraisalService.selectAppraisalList(appraisal);
        ExcelUtil<Appraisal> util = new ExcelUtil<Appraisal>(Appraisal.class);
        util.exportExcel(response, list, "考核申请数据");
    }

    /**
     * 获取考核申请详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:appraisal:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(appraisalService.selectAppraisalById(id));
    }

    /**
     * 新增考核申请
     */
    @PreAuthorize("@ss.hasPermi('system:appraisal:add')")
    @Log(title = "考核申请", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Appraisal appraisal)
    {
        return toAjax(appraisalService.insertAppraisal(appraisal));
    }

    /**
     * 修改考核申请
     */
    @PreAuthorize("@ss.hasPermi('system:appraisal:edit')")
    @Log(title = "考核申请", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Appraisal appraisal)
    {
        return toAjax(appraisalService.updateAppraisal(appraisal));
    }

    /**
     * 删除考核申请
     */
    @PreAuthorize("@ss.hasPermi('system:appraisal:remove')")
    @Log(title = "考核申请", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(appraisalService.deleteAppraisalByIds(ids));
    }
}
